import lejos.nxt.*;

/**
 *
 * @author Pawel Jankowski
 */
public class MotorController {

    public MotorController() {
        Motor.A.smoothAcceleration(false);
        Motor.B.smoothAcceleration(false);

        Motor.A.regulateSpeed(false);
        Motor.B.regulateSpeed(false);
    }

    public void stop() {
        Motor.A.stop();
        Motor.B.stop();
    }

    public void setMotorSpeed(int speed) {
        if (speed < 0) {
            Motor.A.setSpeed(Math.abs(speed));
            Motor.B.setSpeed(Math.abs(speed));
            Motor.A.forward();
            Motor.B.forward();
        } else {
            if (speed > 0) {
                Motor.A.setSpeed(Math.abs(speed));
                Motor.B.setSpeed(Math.abs(speed));
                Motor.A.backward();
                Motor.B.backward();
            } else {
                this.stop();
            }
        }
    }

}
